const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const Router = require('koa-router');
const cors = require('koa2-cors');
const { connectDb, initSchema } = require('./datebase/init.js');

connectDb();
initSchema();
const app = new Koa();

// 解决跨域
app.use(cors());
app.use(bodyParser());


const router = new Router();
const BooksRouter = require('./datebase/api/books');
const UserRouter = require('./datebase/api/user');
const CommentRouter = require('./datebase/api/comment');
router.use('/mpvueBooks/books', BooksRouter.routes());
router.use('/mpvueBooks/user', UserRouter.routes());
router.use('/mpvueBooks/comment', CommentRouter.routes());
app.use(router.routes()).use(router.allowedMethods());

app.listen(3000, () => {
  console.log('server running is %s', 3000);
});